package com.whxy02.tolearn.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.whxy02.tolearn.app.beans.Subject;
import com.whxy02.tolearn.app.dao.SubjectDao;
import com.whxy02.tolearn.app.service.SubjectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

@Service
public class SubjectServiceImpl implements SubjectService {
    private QueryWrapper<Subject> wrapper=new QueryWrapper<>();

    @Resource
    SubjectDao subjectDao;

    @Override
    public List<Subject> getAll() throws Exception {
        return subjectDao.selectList(null);
    }

    @Override
    public Subject getById(Integer id) throws Exception {
        return subjectDao.selectById(id);
    }

    @Override
    public int save(Subject subject) throws Exception {
        return subjectDao.insert(subject);
    }

    @Override
    public int removeById(Integer id) throws Exception {
        return subjectDao.deleteById(id);
    }

    @Override
    public int change(Subject subject) throws Exception {
        return subjectDao.updateById(subject);
    }

    @Override
    public Subject getBySubjectName(String subjectName) throws Exception {

        wrapper.clear();
        wrapper.eq("subject_name",subjectName);
        return subjectDao.selectOne(wrapper);
    }
}
